<?php

class TalentTable extends Doctrine_Table
{
    public function ajaxAutocompleter($value)
    {
        $q = $this->createQuery('t')
                 ->leftJoin('t.PClass c')
                 ->where("(t.name) like (?)", '%'.$value.'%')
                 ->groupBy("c.name")
                 ->orderBy("t.classid");
        $r = $q->execute();
        $json = array();
        foreach ($r as $data)
        {
            if (!in_array($data->__toString(), $json))
                $json[$data->getId()] = $data->__toString()." (".$data->getPClass()->__toString().")";
        }
        return $json;
    }
    
    public function getBackendList(Doctrine_Query $q)
    {
        $rootAlias = $q->getRootAlias();
        $q->leftJoin($rootAlias.".PClass c");
        return $q;
    }
}